package com.atjinggu.jinggumail.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author jingming
 * @Type Cart.java
 * @Desc
 * @date 2021/3/5 11:27
 */
@Data
public class Cart {
    private List<CartItem> cartItems;
    private Integer countType; //商品总类型
    private Integer totalAmount;//商品总件数
    private BigDecimal totalPrice;
    private BigDecimal reduce = new BigDecimal("0.00"); //商品总优惠


    public Integer getCountType() {
        int count = 0;
        for (CartItem cartItem : this.cartItems) {
            count += 1;
        }
        return count;
    }

    public Integer getTotalAmount() {
        int count = 0;
        for (CartItem cartItem : this.cartItems) {
            count += cartItem.getCount();
        }
        return count;
    }


    public BigDecimal getTotalPrice() {
        BigDecimal count = new BigDecimal("0");
        for (CartItem cartItem : this.cartItems) {
            if(cartItem.getCheck()) {
                count = count.add(cartItem.getTotalPrice());
            }
        }
        return  count.subtract(reduce);
    }

}